import java.util.Scanner;

/**
 * @ CLassName GuessNum02
 * @ Author 99036
 * @ Date 2022/2/22 23:54
 */

public class GuessNum02 {
    private static int times = 4;
    private static int a = 0, b = 0;
    private static int[] key = generateKey();

    public static void main(String[] args) {
        while (game()) {
            game();
        }
    }

    public static boolean game() {
        System.out.println("开始输入：（每个数字用#分开）");
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        String[] split = s.split("#");
        if (split.length > 4) System.out.println("输入的数太多了！能不能看提示！");
        for (int i = 0; i < split.length; i++) {
            for (int j = 0; j < split.length; j++) {
                if (Integer.parseInt(split[i]) == key[j] && i == j) a++;
                if (Integer.parseInt(split[i]) == key[j]) b++;
            }
        }
        System.out.println("正确答案：" + arrToString(key));
        System.out.println(a + " A " + b + " B ");
        System.out.println("还要再晚上一盘码，侠士！(输入y继续)");
        String again = scanner.nextLine();
        if ("y".equals(again))
            return true;
        return false;
    }

    public static int[] generateKey() {
        int[] arr = new int[4];
        for (int i = 0; i < arr.length; i++) {
            int random = (int) (1 + Math.random() * 9);
            arr[i] = random;
        }
        return arr;
    }

    public static String arrToString(int a[]) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < a.length; i++) {
            sb.append(a[i]);
        }
        return sb.toString();
    }

}
